package com.ybf.api.service.impl;

import com.github.pagehelper.PageHelper;
import com.ybf.api.entity.PageRequest;
import com.ybf.api.entity.PageResult;
import com.ybf.api.entity.FileDetails;
import com.ybf.api.mapper.FileDetailsMapper;
import com.ybf.api.service.FileDetailsService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ybf
 * @since 2024-09-26
 */
@Service("FileDetailsService")
public class FileDetailsImpl implements FileDetailsService {

    @Resource
    private FileDetailsMapper filedetailsMapper;

    @Override
    public PageResult<FileDetails> list(FileDetails filedetails, PageRequest pageRequest) {
        PageHelper.startPage(pageRequest);
        List<FileDetails> list = filedetailsMapper.list(filedetails);
        PageResult<FileDetails> pageResult = new PageResult<FileDetails>(list);
        return pageResult;
    }

    @Override
    public List<FileDetails> list(FileDetails filedetails) {
        List<FileDetails> list = filedetailsMapper.list(filedetails);
        return list;
    }

    @Override
    public FileDetails info(Integer id) {
        return filedetailsMapper.info(id);
    }

    @Override
    public FileDetails info(String hash) {
        return filedetailsMapper.infoByHash(hash);
    }

    @Override
    public Boolean delete(Integer id) {
        return filedetailsMapper.delete(id) > 0;
    }

    @Override
    public Integer edit(FileDetails filedetails) {
        if (filedetails.getId() != null) {
            return filedetailsMapper.edit(filedetails);
        }
        return filedetailsMapper.add(filedetails);
    }

    @Override
    public Integer add(FileDetails filedetails) {
        filedetails.setCreatedBy(1002);
        return filedetailsMapper.add(filedetails);
    }
}
